home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Reversed fades ƒ / Pour scroll fade reversed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-12  |  3.0 KB  |  113 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Pour scroll fade reversed.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define CorrectTime 2
  32. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  33. #define theWindowWidth (boundsRect.right-boundsRect.left)
  34.  
  35. pascal short PourScrollFadeReversed(Rect boundsRect, Pattern *thePattern);
  36.  
  37. /* Scroll down in tiny strips, starting at the right and moving left.  Scroll
  38.    strips 1-(N), then strips 1-(N+1), etc.  When strip 1 is done, don't do it
  39.    anymore!  (Duh, but this was difficult to get right.)  So only scroll strips
  40.    2-(N), and so on. */
  41.    
  42. pascal short PourScrollFadeReversed(Rect boundsRect, Pattern *thePattern)
  43. {
  44.     Rect            *dest;
  45.     int                *iter;
  46.     Rect            scrollsource;
  47.     int                i;
  48.     int                startstrip,endstrip;
  49.     int                ScrollSize, BoxSize;
  50.     int                NumStrips;
  51.     
  52.     ScrollSize=theWindowHeight/50;
  53.     NumStrips=theWindowWidth/4;
  54.     BoxSize=theWindowWidth/NumStrips;
  55.     dest=(Rect*)NewPtr(sizeof(Rect)*NumStrips);
  56.     if (dest==0L)
  57.         return -1;        /* memory error */
  58.     iter=(int*)NewPtr(sizeof(int)*NumStrips);
  59.     if (iter==0L)
  60.     {
  61.         DisposePtr(dest);
  62.         return -1;        /* memory error */
  63.     }
  64.     
  65.     SetRect(&scrollsource, boundsRect.right-BoxSize, boundsRect.top,
  66.         boundsRect.right, boundsRect.bottom);
  67.         
  68.     for (i=0; i<NumStrips; i++)
  69.     {
  70.         dest[i].top = theWindowHeight-ScrollSize;
  71.         dest[i].bottom=theWindowHeight;
  72.         dest[i].left=theWindowWidth-(i+1)*BoxSize;
  73.         dest[i].right=dest[i].left+BoxSize;
  74.         OffsetRect(&(dest[i]), boundsRect.left, boundsRect.top);
  75.         
  76.         iter[i]=0;
  77.     }
  78.     
  79.     startstrip=0;
  80.     endstrip=1;
  81.     do
  82.     {
  83.         StartTiming();
  84.         
  85.         ScrollRect(&scrollsource, 0, -ScrollSize, 0L);
  86.         
  87.         for (i=startstrip; i<endstrip; i++)
  88.         {
  89.             FillRect(&dest[i], *thePattern);
  90.             iter[i]+=ScrollSize;
  91.         }
  92.         
  93.         if (endstrip<NumStrips)
  94.         {
  95.             endstrip++;
  96.             scrollsource.left-=BoxSize;
  97.         }
  98.         if (iter[startstrip]>=theWindowHeight)
  99.         {
  100.             startstrip++;
  101.             scrollsource.right-=BoxSize;
  102.         }
  103.         
  104.         TimeCorrection(CorrectTime);
  105.     }
  106.     while (startstrip<endstrip);
  107.     
  108.     DisposePtr(dest);
  109.     DisposePtr(iter);
  110.     
  111.     return 0;
  112. }
  113.